<template>
	<view class="custom-nav">
		<view class="top-logo" :style="[{ paddingTop }]">
			<!-- 左侧返回按钮 -->
			<view class="left">
				<uni-icons type="back" :style="[{menuHeight}]" :color="color" size="26" @click="onBack" v-if="back">
				</uni-icons>
				<!-- <uni-icons type="home" :color="color" size="26" @click="onBack" v-if="back" :style="[{ paddingTop }]">
				</uni-icons> -->
			</view>
			<view class="title" :class="isBackTitle?'juzhong':''" :style="[{height:menuHeight}]" v-if="!back||isBackTitle">
				<text class="title-text" v-if="isTitle">{{title}}</text>
				<image src="/static/sj_logo_top.png" mode="aspectFit" class="image" v-else></image>
			</view>

		</view>
		<view :style="{height}"></view>
	</view>
</template>

<script>
	export default {
		name: "topLogo",
		props: {
			title: {
				type: String,
				default: ""
			},
			isTitle: {
				type: Boolean,
				default: true
			},
			isBackTitle: {
				type: Boolean,
				default: false
			},
		},
		data() {
			return {
				height: 0,
				paddingTop: 0,
				menuHeight: 0,
				back: false,
				color: "#FFF"
			};
		},
		created() {
			//#ifdef MP-WEIXIN
			const demo = uni.getMenuButtonBoundingClientRect();
			this.paddingTop = demo.top * 2 + "rpx";
			this.menuHeight = demo.height * 2 + "rpx";
			//#endif
			//#ifdef H5
			this.paddingTop = 10 * 2 + "rpx";
			this.menuHeight = 44 * 2 + "rpx";
			//#endif
			// console.log("paddingTop", this.paddingTop)
			// 状态栏高度
			const statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			// console.log("uni.getSystemInfoSync()", uni.getSystemInfoSync())
			// 导航栏高度(标题栏高度)一般都为44px，所以我这里直接使用44
			// 总体高度 = 状态栏高度 + 导航栏高度
			this.height = (statusBarHeight + 44) * 2 + 'rpx'
			let pages = getCurrentPages()
			// console.log(pages)
			if (pages.length > 0) {
				let prevPage = pages[pages.length - 1]
				if (prevPage.route != 'pages/index/index' && prevPage.route != 'pages/center/index' && prevPage.route !=
					'pages/jiuwu/index' && prevPage.route !=
					'pages/shangquan/index' && prevPage.route !=
					'pages/gongyi/index') {
					this.back = true
				}
			}
		},
		methods: {
			// 左侧返回按钮调用
			//直接返回上一级
			onBack() {
				// this.$emit("onBack");
				uni.navigateBack({
					delta: 1 // 返回的页面数
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	// .top-logo {
	// 	width: 100%;
	// 	display: flex;
	// 	justify-content: center;
	// 	align-items: center;

	// 	.image {
	// 		width: 320rpx;
	// 		height: 71rpx;
	// 	}
	// }

	.top-logo {
		position: absolute;
		width: 100%;
		display: flex;
		// align-items: center;
		// justify-content: center;
		font-size: 26rpx;
		z-index: 100;
		// background: #fff;
		// height: 136rpx;
		// padding-bottom: 10rpx;
		padding: $uni-wrap-padding;

		.left {
			// float: left;
			position: absolute;
			// width: 100rpx;
			line-height: 88rpx;
			height: 88rpx;
			top: 60rpx;
			bottom: 0;
			left: 10rpx;
			margin: auto;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.title {
			padding: 0;
			font-size: 36rpx;
			font-family: Source Han Sans CN;
			height: 88rpx;
			display: flex;
			align-items: center;

			.title-text {
				color: #DF686A;
				font-size: 34rpx;
				font-weight: bold;
			}

			// color: #FFFFFF;
			&.juzhong {
				margin: 0 auto;
				color: #fff;

				.title-text {
					color: #fff;
				}
			}
		}



		.image {
			width: 164rpx;
			height: 48rpx;
		}

	}
</style>